package com.dps.omc.utils.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class CSMySQL extends JdbcService{
	private static final Logger logger = LoggerFactory.getLogger(CSMySQL.class);

	//驱动
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	static
	{
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			logger.error(e.toString());
		}
	}

		private static Connection conn = null;

		public boolean testConnect(JdbcConnect jdbcConnect) {
			//地址
			String URL = "jdbc:"+jdbcConnect.getDbType()+"://"+jdbcConnect.getDbHost()+":"+jdbcConnect.getDbPort()+"/"+jdbcConnect.getDbName();
			//用户名
			String USERNAME = jdbcConnect.getDbUser();
			//密码
			String PWD = jdbcConnect.getDbPass();
			
			try {
				conn = DriverManager.getConnection(URL,USERNAME,PWD);
				return true;
			} catch (SQLException e) {
				logger.error(e.toString());
			}
			finally {
				try {
					if(conn!=null)
					{
						conn.close();
					}
				} catch (SQLException e) {
					logger.error(e.toString());
				}
			}
			return false;			
		}

				
}
